﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using EPiServer.Core;

namespace EPiBoost.Core.Extensions
{
	public static class IContentExtensions
	{
		public static PageReference GetPageReference(this IContent self)
		{
			return self.ContentLink as PageReference;
		}

		public static PageData GetPage(this IContent self)
		{
			var pageReference = self.GetPageReference();
			if(!PageReference.IsNullOrEmpty(pageReference))
			{
				return pageReference.GetPage();
			}
			return null;
		}

		public static PageData GetPage<T>(this IContent self) where T : PageData
		{
			var pageReference = self.GetPageReference();
			if (!PageReference.IsNullOrEmpty(pageReference))
			{
				return pageReference.GetPage<T>();
			}
			return null;
		}

			
	}
}
